<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <!-- 只要出现了v-for,就无脑地加key -->
        <!-- 为了下次能直接复用相同的元素，为了提高渲染的效率 -->
        <!-- key要唯一的, 一定不能使用复杂类型 -->
        <!-- 能不用index的时候尽量不用index -->
        <li v-for="(item, index) in list" :key="item.id">
          {{ item.name }} - <button v-on:click="remove(item.id)">删除</button>
        </li>
      </ul>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            list: [
              {
                id: 1,
                name: "zhangsan",
                obj: { a: 3 },
              },
              {
                id: 2,
                name: "lisi",
                obj: { a: 4 },
              },
              {
                id: 3,
                name: "wangwu",
                obj: { a: 5 },
              },
            ],
          };
        },
        methods: {
          remove(id) {
            this.list = this.list.filter((item) => item.id !== id);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
